package com.bill99.golden.inf.sso.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.bill99.golden.inf.sso.model.AppConfigInfoItem;
import com.bill99.golden.info.sso.model.AppInfo;
import com.bill99.inf.ibatis.Dao;

public class AppInfoData implements IAppInfoData {
	private static Log log = LogFactory.getLog(AppInfoData.class);
	static Map<String, AppConfigInfoItem> appInfoDataMap = new HashMap<String, AppConfigInfoItem>();
	Dao dao;

	public Map<String, AppConfigInfoItem> getAppConfigInfoData() {
		// TODO Auto-generated method stub
		return appInfoDataMap;
	}

	public static Map<String, AppConfigInfoItem> getAppConfigMap() {
		// TODO Auto-generated method stub
		return appInfoDataMap;
	}

	public void init() {
		Map<String,Object> mp = new HashMap<String,Object>();
		mp.put("state", new Long(1));
		appInfoDataMap.clear();
		List list = dao.queryForList("appInfo.queryAppInfo", mp);
		for (int i = 0; i < list.size(); i++) {
			AppInfo ai = (AppInfo) list.get(i);
			AppConfigInfoItem a = new AppConfigInfoItem();
			a.setAppCode(ai.getAppCode());
			a.setAppName(ai.getAppName());
			a.setLogoutUrl(ai.getLogoutUrl());
			appInfoDataMap.put(a.getAppCode(), a);
		}
		log.info("init AppDataInfo:" + appInfoDataMap);
		TokenService.setAppInfoData(this);
	}

	public void setDao(Dao dao) {
		this.dao = dao;
	}
}
